﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace InstaMe
{
    public static class StyleExtensions
    {
        public static T GetPropertyValue<T>(this Style style, DependencyProperty property)
        {
            var setter =
                style.Setters.Cast<Setter>().FirstOrDefault(
                    s => s.Property == property);
            var value = setter != null ? setter.Value : null;

            if (setter == null &&
                style.BasedOn != null)
            {
                value = style.BasedOn.GetPropertyValue<T>(property);
            }
            return (value is T) ? (T)value : default(T);
        }
    }  
}
